<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .layui-card {
            width: 1024px;
            margin: auto;
        }

        .box {
            height: 24px;
            width: 100%;
            padding: 0;
            margin: 0;
        }

        .good-result {
            width: 50%;
            background-color: green;
            float: left;
        }

        .down-result {
            width: 50%;
            background-color: red;
            float: left;
        }

        .layui-btn {
            height: 38px;
            line-height: 38px;
            border: 1px solid transparent;
            padding: 0 18px;
            background-color: #009688;
            color: #fff;
            white-space: nowrap;
            text-align: center;
            font-size: 14px;
            border-radius: 2px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="layui-card">
        <div class="layui-card-header">投票结果</div>
        <div class="layui-card-body">
            <div class="box">
                <div class="good-result">50%</div>
                <div class="down-result">50%</div>
            </div>
            <br>
            <button type="button" class="layui-btn good-btn">赞成</button>
            <button type="button" class="layui-btn down-btn">反对</button>
            <div>
                <p>赞成：<strong class="good-number">0</strong></p>
            </div>
            <div>
                <p>反对：<strong class="down-number">0</strong></p>
            </div>
        </div>
    </div>
    <script>
        //获取DOM
        //结果显示
        let goodDom = document.querySelector('.good-result');
        let downDom = document.querySelector('.down-result');
        //点击按钮
        let goodbtnDom = document.querySelector('.good-btn') ;
        let downbtnDom = document.querySelector('.down-btn');
        //票数显示
        let goodnumDom = document.querySelector('.good-number');
        let downnumDom = document.querySelector('.down-number');
        //点击赞成添加数量、投票结果改变
        goodbtnDom.addEventListener('click',function(){
            goodnumDom.innerHTML= Number(goodnumDom.innerHTML)+1;
            //百分比显示
            goodDom.innerHTML = parseInt(Number(goodnumDom.innerHTML)/(Number(goodnumDom.innerHTML)+Number(downnumDom.innerHTML))*10000)/100 + '%';
            downDom.innerHTML = parseInt(Number(downnumDom.innerHTML)/(Number(goodnumDom.innerHTML)+Number(downnumDom.innerHTML))*10000)/100 + '%';
            //宽度改变
            goodDom.style.width = goodDom.innerHTML
            downDom.style.width = downDom.innerHTML
        })
        downbtnDom.addEventListener('click',function(){
            downnumDom.innerHTML= Number(downnumDom.innerHTML)+1;
            //百分比显示
            goodDom.innerHTML = parseInt(Number(goodnumDom.innerHTML)/(Number(goodnumDom.innerHTML)+Number(downnumDom.innerHTML))*10000)/100 + '%';
            downDom.innerHTML = parseInt(Number(downnumDom.innerHTML)/(Number(goodnumDom.innerHTML)+Number(downnumDom.innerHTML))*10000)/100 + '%';
            //宽度改变
            goodDom.style.width = goodDom.innerHTML
            downDom.style.width = downDom.innerHTML
        })
        
    </script>
</body>

</html>